package Models.dao;

import Models.utils.DataSourceManager;
import org.apache.commons.dbutils.QueryRunner;
import Models.enity.AdminUser;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class AdminUserDao {
    private QueryRunner runner = new QueryRunner(DataSourceManager.getDataSource());
    public AdminUser findByUsername(String username){
        String sql = "SELECT * FROM merchant WHERE username=?";
        try {
            return runner.query(sql,new BeanHandler<AdminUser>(AdminUser.class),username);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  null;
    }

    public int ChangePassword(String id,String Password){
        String sql = "UPDATE admin_user SET password=? WHERE id=?";
        try {
            return runner.update(sql,Password,id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return  -1;
    }
}
